from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options

url = r'https://www.baidu.com/'
driver = webdriver.Chrome(options=options)
driver.get(url)

# 1.id
driver.find_element(By.ID, 'kw').send_keys('selenium')
driver.find_element(By.ID, 'su').click()
sleep(3)

# 2.name
driver.find_element(By.NAME, 'wd').send_keys('selenium2')
driver.find_element(By.ID, 'su').click()
sleep(3)

# 3.tag定位
driver.find_elements(By.TAG_NAME, 'input')[7].send_keys('selenium3')
driver.find_elements(By.TAG_NAME, 'input')[8].click()
sleep(3)

# 4.class定位
driver.find_element(By.CLASS_NAME, 's_ipt').send_keys('s4')
# driver.find_element(By.CLASS_NAME, 'self-btn').click()
driver.find_elements(By.CLASS_NAME, 'bg')[2].click()
sleep(3)


# 5.xpath定位
"""
xpath   基本语法
/       根路径
//      相对路径
*       所有标签
input   指定标签
[@id="kw"] 指定属性

"""

# 5-1.绝对路径
# driver.find_element(By.XPATH, '/html/body/div[2]/div[1]/div[5]/div/div/form/span[1]/input').send_keys('s5')
# driver.find_element(By.XPATH, '/html/body/div[2]/div[1]/div[5]/div/div/form/span[2]/input').click()
# sleep(3)

# 5-2.相对路径
driver.find_element(By.XPATH,'//*[@id="kw"]').send_keys('s6')
driver.find_element(By.XPATH,'//*[@id="su"]').click()
sleep(3)

# 5-2-2:相对路径之指定标签
driver.find_element(By.XPATH,'//input[@id="kw"]').send_keys('s7')
driver.find_element(By.XPATH,'//input[@id="su"]').click()
sleep(3)

# 6.css
driver.find_element(By.CSS_SELECTOR, '#kw').send_keys('s8')
driver.find_element(By.CSS_SELECTOR, '#su').click()
sleep(3)

# 7.link
driver.find_element(By.LINK_TEXT, '新闻').click()
sleep(3)

# 8.partial_link
driver.find_element(By.PARTIAL_LINK_TEXT, '新').click()
sleep(3)

driver.quit()
